package net.xuele.learn.delay;

import java.util.Random;
import java.util.concurrent.DelayQueue;

/**
 * Created by huanghao（HIKARI） on 2019/6/27 0027.
 *
 *
 */
public class Worker {
    public static void main(String[] args) {

        DelayQueue<Message> delayqueue = new DelayQueue<>();
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            Message message = new Message(i, "content" + i, random.nextInt(1000000));
            delayqueue.add(message);
        }



        new Thread(() -> {
            while (true) {
                Message message;
                try {
                    // 此处会调用getDelay方法
                    message = delayqueue.take();
                    System.out.println("message = " + message.getId());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }).start();
    }
}
